import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:hj_crm/const/constant.dart';
import 'package:hj_crm/form/home_page.dart';
import 'package:hj_crm/http/injection.dart';
import 'package:hj_crm/login/user_login.dart';
import 'package:hj_crm/utils/network_cubit.dart';
import 'package:hj_crm/utils/sp_utils.dart';

bool hasToken = false;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Injection.init();

  hasToken = SpUtil.getToken() != null;

  /// 是否为双系统
  Constant.dualSystem = SpUtil.dualSystem();

  NetworkCubit.networkCheck();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      locale: const Locale('zh', 'CN'), // 全局设置语言为中文
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('zh', 'CN'),
      ],
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: hasToken ? const HomePageWidget() : const LoginPageWidget(),
    );
  }
}
